package com.ssyt.wxstore.sys.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ssyt.wxstore.common.BaseAction;
import com.ssyt.wxstore.common.util.FastjsonUtil;
import com.ssyt.wxstore.sys.entity.SysMenu;
import com.ssyt.wxstore.sys.entity.SysRole;
import com.ssyt.wxstore.sys.service.RoleService;

@Controller
@Scope("prototype")
public class RoleAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	@Autowired
	private RoleService roleService;
	private SysRole role;
	private String roleId;
	private String id;
	private String[] menuIds;
	private List<SysMenu> sysMenuList;

	/**
	 * 修改用户权限
	 * 
	 * @throws Exception
	 */
	public void update() throws Exception {
		int row = roleService.update(role, menuIds);
		print(row);
	}

	/**
	 * 获取用户权限
	 * 
	 * @throws Exception
	 */
	public void getUserMenu() throws Exception {
		SysRole sysRole = roleService.getUserMenu(id);
		print(FastjsonUtil.toJson(sysRole));
	}

	/**
	 * 新增角色
	 * 
	 * @throws Exception
	 */
	public void add() throws Exception {
		String rowId = roleService.add(role, menuIds);
		print(rowId);
	}

	/**
	 * 删除角色
	 * 
	 * @throws Exception
	 */
	public void remove() throws Exception {
		int rowId = roleService.remove(roleId);
		print(rowId);
	}

	/**
	 * 获取菜单
	 * 
	 * @throws Exception
	 */
	public void getMenu() throws Exception {
		if (id == null) {
			id = "0";
		}
		List<SysMenu> menuList = roleService.getMenu(id);
		print(FastjsonUtil.toJson(menuList));
	}

	public SysRole getRole() {
		return role;
	}

	public void setRole(SysRole role) {
		this.role = role;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setMenuIds(String[] menuIds) {
		this.menuIds = menuIds;
	}

	public List<SysMenu> getSysMenuList() {
		return sysMenuList;
	}

}
